package com.huluobo.a2207mmonthdemo.live;

import androidx.lifecycle.MutableLiveData;

import com.google.gson.Gson;
import com.huluobo.base.bean.CommonBeanResult;
import com.huluobo.base.bean.GiftBeanResult;
import com.huluobo.base.mvvm.BaseViewModel;
import com.huluobo.base.net.Const;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by LC on 2024/10/9.
 */
public class LiveViewModel extends BaseViewModel<LiveRepo> {
    MutableLiveData<CommonBeanResult> followAuthSuccess = new MutableLiveData<>();
    MutableLiveData<String> followAuthFailed = new MutableLiveData<>();

    MutableLiveData<CommonBeanResult> cancelFollowSuccess = new MutableLiveData<>();
    MutableLiveData<String> cancelFollowFailed = new MutableLiveData<>();
    MutableLiveData<GiftBeanResult> getGiftSuccess = new MutableLiveData<>();
    MutableLiveData<String> getGiftFailed = new MutableLiveData<>();

    public void getGift() {
        repo.getGift(getGiftSuccess, getGiftFailed);
    }

    public void cancelFollow(String authname) {
        Map<String, String> map = new HashMap<>();
        map.put(Const.PARAM_AUTHNAME, authname);
        String json = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(Const.MEDIA_TYPE), json);
        repo.cancelFollow(body, cancelFollowSuccess, cancelFollowFailed);
    }

    public void followAuth(String authname) {
        Map<String, String> map = new HashMap<>();
        map.put(Const.PARAM_AUTHNAME, authname);
        String json = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(Const.MEDIA_TYPE), json);
        repo.followAuth(body, followAuthSuccess, followAuthFailed);
    }

    @Override
    protected LiveRepo createRepo() {
        return new LiveRepo();
    }
}
